﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AlexandriaPressUserBusinessLayer;

namespace AlexandriaPressWebsite.MasterPages.UserPages
{
    public partial class UploadPicturePage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void registerFinish_Click(object sender, EventArgs e)
        {
                if (FileUpload1.HasFile)
                {
                    if (FileUpload1.FileName.Trim().Length > 100)
                    {
                        Label1.Visible = true;
                        Label1.Text = "Please use a shorter file name.";
                    }
                    else
                    {
                        try
                        {
                            string username = (System.Web.HttpContext.Current.Session["username"]).ToString();
                            Label1.Text = UserBusinsessLayer.saveProfilePic(FileUpload1.FileName, Server.MapPath("ProfilePic//" + FileUpload1.FileName), FileUpload1.PostedFile, username);

                        }
                        catch (Exception)
                        {
                            Label1.Text = "File could not be uploaded.";
                        }
                    }
                }        
        }
    }
}
